package com.gravata.enigma.repositorio.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.gravata.enigma.model.Satelite;
import com.gravata.enigma.model.Service;
import com.gravata.enigma.model.Transponder;
import com.gravata.enigma.repositorio.RepositorioGenerico;
import com.gravata.enigma.repositorio.RepositorioService;

public class RepositorioServicoImpl extends RepositorioGenerico<Service>
		implements RepositorioService {

	public RepositorioServicoImpl(Context context) throws SQLException {
		super(context);
	}

	@Override
	public Service obterPorReference(String reference) {

		try {
			Service service=database.queryBuilder().where().eq("reference", reference).queryForFirst();
			return service;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;

	}

	@Override
	public List<Service> filtrarPor(Satelite satelite) {
		List<Service> servicos=new ArrayList<Service>();
		List<Transponder> transponders= new ArrayList<Transponder>(satelite.getTransponders());
		for(Transponder transponder:transponders){
			servicos.addAll(filtrarPor(transponder));
		}

		return servicos;
	}
	@Override
	public List<Service> filtrarPor(Transponder transponder) {
		return listarPorAtributo("transponder_transponder_id", transponder);
	}

}